import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/config/storage_manager.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/custom_list_cell.dart';
import 'package:s_mankey/ui/widget/error_widget.dart';
import 'package:s_mankey/ui/widget/loading_widget.dart';
import 'package:s_mankey/ui/widget/unlogin_nav.dart';
import 'package:s_mankey/view_model/login_vmodel.dart';

class ChooseSource extends StatefulWidget {

  @override
  _ChooseSource createState() => _ChooseSource();
}


class _ChooseSource extends State<ChooseSource> with AutomaticKeepAliveClientMixin{

  var datas;


  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    UnLoginNav(context).unLogin();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    var loginModel = Provider.of<LoginVModel>(context,listen:false);
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        actions: [
          Container(
              padding: EdgeInsets.only(right: 10),alignment: Alignment(0,0),
              child: GestureDetector(onTap: (){
                print('点击了邀请记录');
                Navigator.pushNamed(context, RouterName.inviteRecord);
              },child: Text('邀请记录'),)),
        ],
        elevation: 0,
        title: Text('选择课程'),
      ),
      body: FutureBuilder(future: SmonkeysRepository.fetchMyChooseCity(),builder:
      (BuildContext context, AsyncSnapshot snapshot) {

        /// 请求中
        if (snapshot.connectionState != ConnectionState.done) {
          return LoadingWidget();
        }
        /// 请求结束
        if (snapshot.hasError) {
          // 请求失败，显示错误
          return unLoginErrorTip(errorTip: snapshot.error.toString(), context: context,);
        }

        datas = snapshot.data;
        // 请求成功，显示数据
        return  ListView.builder(
          primary: true,
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemCount: datas.length,
          itemBuilder: (BuildContext context, int index) {
            return
              CustomListViewCell(
                rootString: RouterName.chooseSource1,
                arguments: {'city': datas[index]['city']},
                index: index,
                title: datas[index]['city_name'],
                subTitle: '',
                trailing: IconFonts.rightIcon,
              );
          },
        );
      }
      ),


    );
  }


}




